package com.qb.baselibrary.basekotlin.http;
import org.json.JSONObject;
import java.util.Map;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RequestConverter {

    private static JSONObject converterJSONObject(Map<String, Object> map){

        return new JSONObject(map);
    }

    private static JSONObject converterJSONObjectS(Map<String, String> map){
        return new JSONObject(map);
    }

    public static RequestBody converterRequestBody(Map<String,Object> map){
        return RequestBody.create(MediaTypes.APPLICATION_JSON_TYPE, converterJSONObject(map).toString());
    }

    public static RequestBody converterRequestBodyS(Map<String,String> map){
        return RequestBody.create(MediaTypes.APPLICATION_JSON_TYPE, converterJSONObjectS(map).toString());
    }

    public static RequestBody converterRequestBody(Map<String,Object> map, MediaType mediaType){
        return RequestBody.create(mediaType, converterJSONObject(map).toString());
    }

    public static RequestBody converterRequestBodyS(Map<String,String> map, MediaType mediaType){
        return RequestBody.create(mediaType, converterJSONObjectS(map).toString());
    }

}
